import { createStore, applyMiddleware, compose, combineReducers } from 'redux';
import promiseMiddleware from 'redux-promise-middleware';
import thunkMiddleware from 'redux-thunk';
import loggerMiddleware from './logger';
import stateA, { STATE_A } from 'modules/a/a.reducer';

export interface IRootState {
    stateA: STATE_A;
}
export const rootReducer = combineReducers({
    stateA
});

const defaultMiddlewares = [promiseMiddleware, thunkMiddleware];
const composedMiddlewares = (middlewares: Array<any>) => {
    if (process.env.NODE_ENV === 'development') {
        return compose(applyMiddleware(...defaultMiddlewares, ...middlewares, loggerMiddleware));
    }
    return compose(applyMiddleware(...defaultMiddlewares, ...middlewares));
};

export default createStore(rootReducer, composedMiddlewares([]));
